<template>
  <div class="picList">
    <!-- 顶部滑动条区域 -->
    <div id="slider" class="mui-slider">
      <div
        id="sliderSegmentedControl"
        class="mui-scroll-wrapper mui-slider-indicator mui-segmented-control mui-segmented-control-inverted"
      >
        <div class="mui-scroll">
          <a
            :class="['mui-control-item',item.id==1?'mui-active':'']"
            v-for="item in categoryList"
            :key="item.id"
            @click="getPicList(item.id)"
          >{{item.category}}</a>
        </div>
      </div>
    </div>
    <ul class="pic">
      <router-link :to="'/home/photoInfo/'+item.id" tag="li" v-for="item in picList" :key="item.id">
        <img v-lazy="item.url" />
        <div class="photoInfo">{{item.title}}---{{item.id}}</div>
      </router-link>
    </ul>
  </div>
</template>

<script>
// 1. 导入 mui 的js文件
import mui from "../../lib/mui/js/mui.min.js";

export default {
  data() {
    return {
      categoryList: "",
      picList: ""
    };
  },
  methods: {
    getCategory() {
      this.$http.get("picCategory").then(res => {
        this.categoryList = res.body;
      });
    },
    getPicList(id) {
      this.$http.get("picList/" + id).then(res => {
        this.picList = res.body.message;
      });
    }
  },
  created() {
    this.getCategory();
    this.getPicList(1);
  },
  mounted() {
    mui(".mui-scroll-wrapper").scroll({
      deceleration: 0.0005 //flick 减速系数，系数越大，滚动速度越慢，滚动距离越小，默认值0.0006
    });
  }
};
</script>

<style lang="less" scoped>
* {
  touch-action: pan-y;
}

.picList {
  img[lazy="loading"] {
    width: 40px;
    height: 300px;
    margin: auto;
  }
  ul {
    padding: 0;
    margin: 0;
    li {
      position: relative;
      list-style: none;
      margin: 10px;
      box-shadow: 0 0 9px #999;
      img {
        width: 100%;
      }
      .photoInfo {
        position: absolute;
        bottom: 0;
        left: 0;
        right: 0;
        height: 50px;
        line-height: 50px;
        text-align: center;
        color: #fff;
        background: rgba(0, 0, 0, 0.5);
      }
    }
  }
}
</style>
